#include <iostream>
#include <limits>

using std::cout;
using std::endl;

//复数i^2 = -1
class Complex
{
public:
    Complex(double dreal = 0, double dimag = 0)
    : _dreal(dreal)
    , _dimag(dimag)
    {
        cout << "Complex(double = 0, double = 0)" << endl;
    }

    void print() const
    {
        cout << _dreal << " + " << _dimag << "i" << endl;
    }

    //获取实部与虚部
    double getReal() const
    {
        return _dreal;
    }

    double getImag() const
    {
        return _dimag;
    }

    ~Complex()
    {
        cout << "~Complex()" << endl;
    }

private:
    double _dreal;
    double _dimag;
};

#if 0
int operator+(int a, int b)
{

}
#endif

/* Z = X + Y; */

//对于运算符重载而言，要确定函数的名字（这个比较简单），然后需要
//确定函数的参数列表，最后确定函数的返回类型
//1、运算符重载的第一种形式：运算符重载之普通函数的形式
Complex operator+(const Complex &lhs, const Complex &rhs)
{
    cout << "Complex operator+(const Complex &, const Complex &)" << endl;
    return Complex(lhs.getReal() + rhs.getReal(),
                   lhs.getImag() + rhs.getImag());
}

void test()
{
    Complex c1(1, 2);
    cout << "c1 = ";
    c1.print();

    cout << endl;
    Complex c2(3, 4);
    cout << "c2 = ";
    c2.print();

    cout << endl;
    Complex c3 = c1 + c2;
    cout << "c3 = ";
    c3.print();
}

int main(int argc, char **argv)
{
    test();
    return 0;
}



